package com.lyy.java_chatroom.api;

import com.lyy.java_chatroom.mapper.MessageMapper;
import com.lyy.java_chatroom.model.Message;
import com.lyy.java_chatroom.model.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

@RestController
public class MessageApi {
    @Resource
    private MessageMapper messageMapper;

    //获取与某好友的聊天记录
    @RequestMapping("/message")
    public Result getMessage(int sessionId){
        List<Message> messages=messageMapper.getMessagesBySessionId(sessionId);
        //从数据库直接查询到的是按照时间降序排列的，实际界面上显示的是升序的结果
        Collections.reverse(messages);
        return Result.success(messages);
    }
}
